import Vue from 'vue';
import qs from 'qs';
// localhost
// export const ApiUrl = 'http://localhost:56776/api/Process';
// 測試API地址
// export const ApiUrl = 'http://10.68.2.9/Process/api/Process';
// 正式API地址
// export const ApiUrl = 'http://mo.centanet.com/ProcessApi/api/Process';
// 獲取代辦事宜列表
export const applyList = (_this, apiName, params, varName, callBack) => {
  let name = varName.split('[')[0];
  let index = varName[varName.length - 2];
  let postData = {
    data: {
      StaffNo: _this.getUserInfo().StaffNo,
      PageIndex: 1,
      PageSize: 8
    }
  };
  for (let item in params) {
    postData.data[item] = params[item];
  }
  _this.axios.post(apiName, qs.stringify(postData))
  .then((res) => {
    Vue.set(_this[name], index, res.data.data);
    setTimeout(() => {
      if (typeof callBack === 'function') {
        callBack();
      }
    }, 1000);
  })
  .catch((err) => {
    Vue.set(_this[name], index, []);
    setTimeout(() => {
      if (typeof callBack === 'function') {
        callBack();
      }
    }, 1000);
    console.log(err);
  });
};
